﻿#include <iostream>
#include <iomanip>
#include <string>
#include "ComputeDoubleSum.h"
#include "ComputeIntSum.h"
#include <locale>
#include "windows.h"
using namespace std;

void ClearStream()
{
	cin.clear();
	cin.sync();
}

void Task1A() 
{
	cout<<"Please enter three int numbers.."<<endl;
	ComputeIntSumm *summInt = new ComputeIntSumm();
	cout<<"Answear "<<summInt->Summ()<<endl;
}

void Task1B()
{
	cout<<"Please enter three double numbers.."<<endl;
	ComputeDoubleSumm *summDouble = new ComputeDoubleSumm();
	cout<<"Answear "<<summDouble->Summ()<<endl;
}

void Task2()
{
	setlocale(LC_ALL, "Russian");
	int x, y, z;
	cout<<"Enter three int numbers."<<endl;
	cin>>x>>y>>z;
	cin.sync();
	char one[10];
	char two[10];
	char three[10];
	cout<<"Enter first string."<<endl;
	cin.getline(one, 10);
	cout<<"Enter next string."<<endl;
	cin.getline(two, 10);
	cout<<"Enter third string."<<endl;
	cin.getline(three, 10);
	cout<<one<<right<<setfill('.')<<setw(25)<<x<<endl;
	cout<<two<<right<<setfill('.')<<setw(25)<<y<<endl;
	cout<<three<<right<<setfill('.')<<setw(25)<<z<<endl;
}

void Task3()
{
	int x;
	double y;
	cout<<"Enter int number"<<endl;
	cin>>x;
	cout<<"Enter double number"<<endl;
	cin>>y;

	cout<<""<<endl;
	cout<<"X"<<endl;
	cout<<oct<<x<<endl;
	cout<<hex<<x<<endl;
	cout<<""<<endl;
	cout<<"Y"<<endl;
	cout<<scientific<<y<<endl;
	cout<<fixed<<setprecision(1)<<y<<endl;
	cout<<fixed<<setprecision(2)<<y<<endl;
	cout<<fixed<<setprecision(3)<<y<<endl;
}

void Task4()
{
	double x;
	cout<<""<<endl;
	cout<<"Enter double number"<<endl;
	cin>>x;
	cout<<fixed<<setprecision(1)<<right<<x<<endl;
	cout<<fixed<<setprecision(2)<<right<<x<<endl;
	cout<<fixed<<setprecision(3)<<right<<x<<endl;
	cout<<fixed<<setprecision(4)<<right<<x<<endl;
}

void Task5A()
{
	setlocale(LC_ALL,"Russian");
	char str1[6];
	char str2[5];
	cin.getline(str1,5);
	cin.getline(str2,3);
	cout<<endl<<"str1 = "<<str1;
	cout<<endl<<"str2 = "<<str2<<endl;
	cout.flush();
}

void Task5B()
{
	setlocale(LC_ALL,"Russian");
	char str1[5];
	char str2[3];
	cin.getline(str1,5);
	cin.clear();//очищает состояние потока.
	cin.getline(str2,3);
	cout<<endl<<"str1 = "<<str1;
	cout<<endl<<"str2 = "<<str2<<endl;
	cout.flush();
}

void Task6()
{
	int x1, y1, x2, y2;
	cout<<"Enter x1 y1"<<endl;
	cin>>x1>>y1;
	cout<<"Enter x2 y2"<<endl;
	cin>>x2>>y2;
	cout<<"coordinates of the segment ("<<x1<<","<<y1<<") "<<"("<<x2<<","<<y2<<")"<<endl;
}

void Task7()
{
	cout<<"Enter string"<<endl;
	char str[8];
	cin.getline(str, sizeof(str), 'g');
	cout<<str<<endl;
}

void Task8()
{
	cout<<"Enter string"<<endl;
	char one;
	char two;
	string s;
	cin>>one>>two>>s;
	cout<<"char one: "<<one<<endl;
	cout<<"char two: "<<two<<endl;
	cout<<"string: "<<s<<endl;
}

void Task9()
{
	string firstQu = "What date is today?";
	string secondQu = "What is the weather today?";
	string thirdQu = "How are you?";
	char answOne[20], answTwo[20], answThree[20];
	cout<<firstQu<<endl;
	cin.getline(answOne, sizeof(answOne));
	cout<<secondQu<<endl;
	cin.getline(answTwo, sizeof(answTwo));
	cout<<thirdQu<<endl;
	cin.getline(answThree, sizeof(answThree));
	system("cls");
	cout<<right<<"|"<<setfill('-')<<setw(50)<<"|"<<endl;
	cout.fill(NULL);
	cout<<right<<"1) "<<firstQu<<endl;
	cout<<right<<setw(50)<<answOne<<endl;
	cout<<right<<"2) "<<secondQu<<endl;
	cout<<right<<setw(50)<<answTwo<<endl;
	cout<<right<<"3) "<<thirdQu<<endl;
	cout<<right<<setw(50)<<answThree<<endl;
	cout<<right<<"|"<<setfill('-')<<setw(50)<<"|"<<endl;
}

void Task10()
{
	char old = 's';
	wchar_t wi = 'Ф';
	cout<<"size of char: "<<sizeof(old)<<endl;
	cout<<"size of wide char: "<<sizeof(wi)<<endl;
}

void Menu()
{
	system("cls");
	cout.setf(ios :: dec);
	cout << right << "1)" << " Task 1 (Add)" << endl;
	wcout << right << "2)" << " Task 2 (output lines)" << endl;
	wcout << right << "3)" << " Task 3 (hex)" << endl;
	wcout << right << "4)" << " Task 4 (pin x)" << endl;
	wcout << right << "5)" << " Task 5 (line)" << endl;
	wcout << right << "6)" << " Task 6 (coordinates)" << endl;
	wcout << right << "7)" << " Task 7 (string input to g)" << endl;
	wcout << right << "8)" << " Task 8 (the first two - characters)" << endl;
	wcout << right << "9)" << " Task 9 (poll)" << endl;
	wcout << right << "a)" << " Task 10 (wide character)" << endl;
	wcout << right << "0)" << " Exit the program" << endl;
	char ch;
	cin.get (ch);
	ClearStream();
	switch (ch)
	{
	case '1':
		{
			system ("cls");
			wcout << "Select integers or real numbers" << endl;
			wcout << "1) The int " << endl;
			wcout << "2) The real " << endl;
			char c1;
			cin.get (c1);
			ClearStream();
			switch (c1)
			{
			case '1':
				{
					system("cls");
					Task1A();
				}
				break;
			case '2':
				{
					system("cls");
					Task1B();
				}
				break;
			}
			ClearStream();
			wcout <<"Press any key..." << endl;
			cin.get();
		}
		break;
	case '2':
		{
			ClearStream();
			system ("cls");
			Task2();
			ClearStream();
			wcout <<"Press any key..." << endl;
			cin.get();
		}
		break;
	case '3':
		{
			ClearStream();
			system("cls");
			Task3();
			ClearStream();
			wcout << "Press any key..." << endl;
			cin.get();
		}
		break;
	case '4':
		{
			ClearStream();
			system ("cls");
			Task4();
			ClearStream();
			wcout << "Press any key " << endl;
			cin.get();
		}
		break;
	case '5':
		{
			system("cls");
			wcout << "Select the program " << endl;
			wcout << "1) The first" << endl;
			wcout << "2) The second" << endl;
			char c1;
			cin.get (c1);
			ClearStream();
			switch (c1)
			{
			case '1':
				{
					system("cls");
					Task5A();
				}
				break;
			case '2':
				{
					system("cls");
					Task5B();
				}
				break;
			}
			ClearStream();
			wcout <<"Press any key..." << endl;
			cin.get();
		}
		break;
	case '6':
		{
			ClearStream();
			system ("cls");
			Task6();
			ClearStream();
			wcout << "Press any key..." << endl;
			cin.get();
		}
		break;
	case '7':
		{
			ClearStream();
			system ("cls");
			Task7();
			ClearStream();
			wcout <<"Press any key..." << endl;
			cin.get();
		}
		break;
	case '8':
		{
			ClearStream();
			system("cls");
			Task8();
			ClearStream();
			wcout << "Press any key..." << endl;
			cin.get();
		}
		break;
	case '9':
		{
			ClearStream();
			system ("cls");
			Task9();
			ClearStream();
			wcout << "Press any key..." << endl;
			cin.get();
		}
		break;
	case 'a':
		{
			ClearStream();
			system("cls");
			Task10();
			ClearStream();
			wcout << "Press any key..." << endl;
			cin.get();
		}
		break;
	case '0':
		{
			exit (0);
		}
		break;
	}
}

int main()
{	
	while (true)
	{
		Menu();
	}
}